package letsjava.unclassified;

import java.math.BigDecimal;

public class Calculator {
	public static abstract class  Operation{
		private String name;
		public Operation(String name){
			this.name = name;
		}
		public String toString(){
			return name;
		}
		
		abstract BigDecimal eval(BigDecimal a, BigDecimal b);
		
		public static final Operation PLUS = new Operation("+"){
			BigDecimal eval(BigDecimal a,BigDecimal b){
				return a.add(b);
			}
		};
		public static final Operation MINUS = new Operation("-"){
			BigDecimal eval(BigDecimal a,BigDecimal b){
				return a.subtract(b);
			}
		};
		public static final Operation TIMES = new Operation("*"){
			BigDecimal eval(BigDecimal a,BigDecimal b){
				return a.multiply(b);
			}
		};
		public static final Operation DIVIDE = new Operation("/"){
			BigDecimal eval(BigDecimal a,BigDecimal b){
				return a.divide(b);
			}
		};
	}
	
	public BigDecimal calculate(BigDecimal a,Operation op, BigDecimal b){
		return op.eval(a, b);
	}
	
	public static void main(String[] args){
		Calculator ca = new Calculator();
		BigDecimal a = new BigDecimal("1.01");
		BigDecimal b = new BigDecimal("0.01");
		
		System.out.println(ca.calculate(a, Operation.PLUS, b));
		System.out.println(ca.calculate(a, Operation.MINUS, b));	
		System.out.println(ca.calculate(a, Operation.TIMES, b));	
		System.out.println(ca.calculate(a, Operation.DIVIDE, b));	
		
	}
}
